﻿@using eCommerce.Core.Domain.Messges
@model eCommerce.Controllers.ShowItemModel

@{
    ViewBag.Title = "ShowItem";
}
<style>
    .goods-info-box {
    }
   
    .pattribute {
        /*clear: both;*/
    }
    .iattribute {
        clear: both;
    }
        .goods-info-box .colorli {
            float: left;
            position: relative;
            margin-right: 10px;
            margin-top: 10px;
            width: 32px;
        }

        .goods-info-box a {
            display: block;
            border: 1px solid #c3c3c3;
            text-align: center;
            padding: 4px;
            width: 35px;
            height: 35px;
        }

        .goods-info-box .square {
            width: 25px;
            height: 25px;
            background-color: #f3f3f3;
        }



        .goods-info-box a img {
            position: absolute;
            left: 5px;
            top: 5px;
        }
</style>

<div class="container">
    <div class="row">
        <div class="col-lg-8">
            <img style="width:100%" src="/Content/images/thumbs/0000005.jpeg" />
        </div>

        <div class="col-lg-3">

            <div>

                @Model.ItemName

             
            </div>

            <div class="pattribute clearfix">
                <div class="goods-info-box">
                    @foreach (var productAttributeModel in Model.ProductAttributeModels)
                    {
                        <div class="colorli">

                            <a href="@productAttributeModel.ItemUrl">
                                @if (string.IsNullOrEmpty(productAttributeModel.IconUrl))
                                {

                                    <span>
                                        @productAttributeModel.AttributeValue
                                    </span>
                                }
                                else
                                {
                                    <img class="square" src="@productAttributeModel.IconUrl" />
                                }
                                

                            </a>
                        </div>
                    }
                </div>
            </div>
            <div class="iattribute clearfix">
                <div class="goods-info-box">
                    @foreach (var itemAttributeModel in Model.ItemAttributeModels)
                    {
                        if (!string.IsNullOrEmpty(itemAttributeModel.AttributeValue))
                        {
                            <div class="colorli">
                                <a data="@itemAttributeModel.ItemCode" class="changeItemCode" style="cursor: pointer">
                                    @itemAttributeModel.AttributeValue
                                </a>
                            </div>

                        }
                    }
                </div>
            </div>
            
            <div>
                @if (Model.UseItemAttribute)
                {
                    <a id="addToCartBtn" data>@T(MessageName.AddToCart)</a>
                }
                else
                {
                    <a id="addToCartBtn" data="Model.ItemAttributeModels.FirstOrDefault().ItemCode">@T(MessageName.AddToCart)</a>
                }
            </div>
        </div>
    </div>
   

</div>

@section scripts
{
    <script>
        $(document).ready(function () {
            $('#addToCartBtn').click(function() {
                var itemId= $(this).attr("data");
                var obj =
                {                    
                    ItemId: itemId,
                    Quantity:1,
                };
                $.ajax({
                    url: "/api/ShoppingCartApi/AddCart",
                    type: 'post',
                    data: ko.toJSON(obj),
                    contentType: 'application/json',
                    success: function (result) {

                        if (result.Status == "0") {
                            alert("保存成功");
                        } else {
                            // alert("保存失败：" + result.Msg);

                            toastr.error(result.Message);
                        }
                    }
                });

            });
            $('.changeItemCode').click(function () {
                var itemCode = $(this).attr("data");
                $('#addToCartBtn').attr('data', itemCode);
            });
        });

        function addToCart() {

        }
    </script>
}
